package org.window;

import com.scm.all.export.ByteUtils;
import com.scm.all.export.SystemUtils;
import com.scm.all.export.WindowOperationUtils;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.CheckBox;

/**
 * 选择框是否为16进制
 */
public class PaneAndHBoxFrameAndColumnVBoxAndHBoxInputValueAndCheckBox {
    public static CheckBox checkBox = new CheckBox();
    public static void init(){
        checkBox.setText("HEX");
        checkBox.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                if(PaneAndHBoxFrameAndColumnVBoxAndHBoxInputValueAndTextFieId.textField.getText().length()>0){
                    try {
                        if(checkBox.isSelected()){
                            PaneAndHBoxFrameAndColumnVBoxAndHBoxInputValueAndTextFieId.textField.setText(ByteUtils.longToByteHex(Long.parseLong(PaneAndHBoxFrameAndColumnVBoxAndHBoxInputValueAndTextFieId.textField.getText())));
                        }else {
                            PaneAndHBoxFrameAndColumnVBoxAndHBoxInputValueAndTextFieId.textField.setText(""+ByteUtils.hexToLong1(PaneAndHBoxFrameAndColumnVBoxAndHBoxInputValueAndTextFieId.textField.getText()));
                        }
                    }catch (NumberFormatException e){
                        SystemUtils.messageBoxExW(WindowOperationUtils.windowGetHwnd(),"该功能不支持小数,仅适用于指针地址转换","温馨提示",0);
                        PaneAndHBoxFrameAndColumnVBoxAndHBoxInputValueAndTextFieId.textField.setText("");
                        checkBox.setSelected(false);
                    }
                }
            }
        });
    }
}
